package com.jeff.tianti.cms.dao;

import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jeff.tianti.cms.entity.Report;
import com.jeff.tianti.cms.dto.ReportQueryDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @author xujianfang
 * @desc ReportDaoImpl��
 * @date 2019-07-05
 */

public class ReportDaoImpl extends CustomBaseSqlDaoImpl implements ReportDaoCustom {

    public PageModel<Report> queryReportPage(ReportQueryDTO reportQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from Report t where 1=1 ");
        if (reportQueryDTO != null) {
            String auditFlag = reportQueryDTO.getAuditFlag();
            if (StringUtils.isNotBlank(auditFlag) && !"-1".equals(auditFlag)) {
                hql.append(" and t.auditFlag = :auditFlag ");
                map.put("auditFlag", auditFlag);
            }
        }
        hql.append(" order by t.createDate desc ");
        return this.queryForPageWithParams(hql.toString(), map, reportQueryDTO.getCurrentPage(), reportQueryDTO.getPageSize());
    }

    public List<Report> queryReportList(ReportQueryDTO reportQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from Report t ");
        return this.queryByMapParams(hql.toString(), map);
    }


}